import SMERouter from "sme-router";
import index from "../controller/index.js";
import login from "../controller/login.js";

const router=new SMERouter("root");

//配置路由中间件
router.use(()=>{
    //判断用户有无登录
    $.ajax({
        url:"/api/users/isAuth",
        type:"get",
        headers:{
            "X-Access-Token":localStorage.getItem("lg-token")||""
        },
        success(res){
            // console.log(res);
            router.go("/index");
        },
        error(err){
            console.log(err);
            router.go("/");
        }
    });
});

router.route("/",login(router));
router.route("/index",index(router));

export default router;